package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.domain.SysStore;
import com.ruoyi.system.service.ISysOrderService;
import com.ruoyi.web.controller.utils.JR;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2022-01-19
 */
@Controller
@RequestMapping("/system/order")
public class SysOrderController extends BaseController
{
    private String prefix = "system/order";

    @Autowired
    private ISysOrderService sysOrderService;

    @RequiresPermissions("system:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询订单列表
     */
    @RequiresPermissions("system:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysOrder sysOrder)
    {
        startPage();
        List<SysOrder> list = sysOrderService.selectSysOrderList(sysOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("system:order:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysOrder sysOrder)
    {
        List<SysOrder> list = sysOrderService.selectSysOrderList(sysOrder);
        ExcelUtil<SysOrder> util = new ExcelUtil<SysOrder>(SysOrder.class);
        return util.exportExcel(list, "全部订单列表");
    }


    /**
     * 获取系统订单详情
     * @param sysOrderNo
     * @return
     */
    @GetMapping("/orderInfo/{sysOrderNo}")
    public JR edit(@PathVariable("sysOrderNo") String sysOrderNo)
    {
        SysOrder sysOrder = sysOrderService.getInfoBySysOrderNo(sysOrderNo);
        return JR.ok(sysOrder);
    }


}
